#include "RB_Tree.h"

namespace My
{
    template<class K, class V>
    class map
    {
        struct KeyMap 
        {   
            const K& operator()(const pair<K, V>& key)
            {
                return key.first;
            }
        };
    public:
        typedef typename RB_Tree<K, pair<K, V>, KeyMap>::iterator iterator;
        iterator begin() { return _tree.begin(); }
        iterator end() { return _tree.end(); }

        pair<iterator, bool> insert(const pair<K, V>& kv) { return _tree.insert(kv); }
        
        V& operator[](const K& k)
        {
            pair<iterator, bool> ret = insert(make_pair(k, V()));
            return ret.first->second;
        }

    private:
        RB_Tree<K, pair<K, V>, KeyMap> _tree;
    };
}
